package operator;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Version: 1.1
 * Author: TangJun
 * Date: 2024-07-18
 */
public class DelOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("开始删除图书");
        System.out.println("请输入你要删除的书名");
        Scanner scan = new Scanner(System.in);
        String name = scan.next();

        int index = findIndex(bookList, name);
        if (index >= 0) {
            for (int i = index; i < bookList.getSize() - 1; i++) {
                Book book = bookList.getPos(i + 1);
                bookList.setPos(book, i);
            }
            System.out.println("删除成功");
            bookList.setSize(bookList.getSize() - 1);
            return;
        }
        System.out.println("找不到这本书，无法删除");
    }
}
